/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018.10.30     SummerGift   first version
 */

#ifndef __DRV_UART_H__
#define __DRV_UART_H__

#include <rtthread.h>
#include "rtdevice.h"
#include <rthw.h>
#include <drv_common.h>
#include "nuc970_uart.h"
#include "nuc970_sys.h"

typedef void(*uart_isr_cb)(int, void*);

/* nuc970 config class */
struct nu_uart_config
{
    const char *name;
    UART_TypeDef *Instance;
    IRQn_Type irq_type;
    uart_isr_cb isr_cb;
    struct dma_config *dma_rx;
    struct dma_config *dma_tx;
};

/* nuc970 uart dirver class */
struct nu_uart_device
{
    struct rt_serial_device serial;
    UART_HandleTypeDef handle;
    struct nu_uart_config *config;

#ifdef RT_SERIAL_USING_DMA
#endif
    rt_uint16_t uart_dma_flag;
};

#if defined(BSP_USING_UART0)
#ifndef UART0_CONFIG
#define UART0_CONFIG                                                \
    {                                                               \
        .name = "uart0",                                            \
        .Instance = UART0,                                          \
        .irq_type = UART0_IRQn,                                     \
        .isr_cb = nu_uart_isr0,                                     \
    }
#endif /* UART0_CONFIG */

#endif /* BSP_USING_UART0 */

#if defined(BSP_USING_UART1)
#ifndef UART1_CONFIG
#define UART1_CONFIG                                                \
    {                                                               \
        .name = "uart1",                                            \
        .Instance = UART1,                                          \
        .irq_type = UART1_IRQn,                                     \
        .isr_cb = nu_uart_isr1,                                     \
    }
#endif /* UART1_CONFIG */

#endif /* BSP_USING_UART1 */

#if defined(BSP_USING_UART4)
#ifndef UART4_CONFIG
#define UART4_CONFIG                                                \
    {                                                               \
        .name = "uart4",                                            \
        .Instance = UART4,                                          \
        .irq_type = UART4_IRQn,                                     \
        .isr_cb = nu_uart_isr1,                                     \
    }
#endif /* UART4_CONFIG */

#endif /* BSP_USING_UART4 */

#if defined(BSP_USING_UART6)
#ifndef UART6_CONFIG
#define UART6_CONFIG                                                \
    {                                                               \
        .name = "uart6",                                            \
        .Instance = UART6,                                          \
        .irq_type = UART6_IRQn,                                     \
        .isr_cb = nu_uart_isr1,                                     \
    }
#endif /* UART6_CONFIG */

#endif /* BSP_USING_UART6 */

int rt_hw_usart_init(void);

#endif  /* __DRV_UART_H__ */
